package com.extension.company.view.home.hotactivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.extension.company.admin.R;
import com.extension.company.common.mvp.BaseActivity;
import com.extension.company.contract.home.HotEventTopContract;
import com.extension.company.presenter.home.HotEventTopPresenter;
import com.extension.company.view.adapter.ItemTitlePagerAdapter;
import com.extension.company.view.details.GoodsCommentFragment;
import com.extension.company.common.widget.NoScrollViewPager;
import com.gxz.PagerSlidingTabStrip;
import com.jaeger.library.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * create zwk
 * data   2019/2/19
 * 描述：商品详情页activity
 */

public class HotActivityDetailActivity extends BaseActivity<HotEventTopContract.View, HotEventTopPresenter>
		implements HotEventTopContract.View {

	public TextView tv_title;
	@BindView(R.id.iv_back)
	ImageView ivBack;
	@BindView(R.id.ll_back)
	LinearLayout llBack;
	@BindView(R.id.psts_tabs)
	PagerSlidingTabStrip pstsTabs;
	@BindView(R.id.tv_title)
	TextView tvTitle;
	@BindView(R.id.ll_title_root)
	LinearLayout llTitleRoot;
	@BindView(R.id.vp_content)
	NoScrollViewPager vpContent;

	private List<Fragment> fragmentList = new ArrayList<>(); // Fragment 集合
	private GoodsInfoFragment goodsInfoFragment;  // 商品详情Fragment
	private GoodsCommentFragment goodsCommentFragment; // 商品评论Fragment


	public static void startActivity(Activity activity, int type) {
		Intent intent = new Intent(activity, HotActivityDetailActivity.class);
		intent.putExtra("type", type);
		activity.startActivity(intent);
	}

	@Override
	public int getMainLayout() {
		return R.layout.activity_hot_event_top;
	}

	@Override
	protected void initData() {
		initView();

		int type = getIntent().getIntExtra("type", 0);
		int  goodId = getIntent().getIntExtra("goodid",0);
		fragmentList.add(goodsInfoFragment = new GoodsInfoFragment());  // 商品详情的Fragment
		fragmentList.add(goodsCommentFragment = new GoodsCommentFragment()); // 评价的Fragment

		Bundle bundle = new Bundle();
		bundle.putInt("type", type);
		bundle.putInt("goodid", goodId);
		goodsInfoFragment.setArguments(bundle);

		vpContent.setAdapter(new ItemTitlePagerAdapter(getSupportFragmentManager(),
				fragmentList, new String[]{"商品", "评价"}));
		vpContent.setOffscreenPageLimit(3);
		pstsTabs.setViewPager(vpContent);

	}

	private void initView() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
			this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE
					| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
		} else {
			StatusBarUtil.setColor(this, getResources().getColor(R.color.black2));
		}
	}

	@Override
	protected void initListener() {

	}

	@Override
	public HotEventTopContract.View createView() {
		return this;
	}

	@Override
	public HotEventTopPresenter createPresenter() {
		return new HotEventTopPresenter();
	}


	@Override
	public void showLoading() {

	}

	@Override
	public void hideLoading() {

	}

	@Override
	public void onError(Throwable throwable) {

	}

	@OnClick({R.id.iv_back})
	public void onViewClicked(View view) {
		switch (view.getId()) {
			case R.id.iv_back:
				finish();
				break;
			default:
				break;
		}
	}
}